<?php

class Exception_Xml
    extends Exception
    implements XMLSerializable {

    public function __construct(LibXMLError $oError) {

        $sMessage = "";

        switch($oError->level) {

            case LIBXML_ERR_WARNING:
                $sMessage .= "Warning";
            break;

            case LIBXML_ERR_ERROR:
                $sMessage .= "Error";
            break;

            case LIBXML_ERR_FATAL:
                $sMessage .= "Fatal error";
            break;

        }

        $sMessage .= " " . $oError->code . ": ";

        $sMessage .= trim($oError->message) . "\nLine: " . $oError->line . "\nColumn: " . $oError->column;

        if($oError->file) {
            $sMessage .= "\nFile: " . $oError->file;
        }

        parent::__construct($sMessage);

    }

    public function toXML() {

    	return "<error type=\"xml\">" . $this->getMessage() . "</error>";

	}

}

?>